package com.empire.module.sporttery.service.football500ouzim;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.football500ouzim.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500ouzim.Football500OuzImDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.football500ouzim.Football500OuzImMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 亚盘实时 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class Football500OuzImServiceImpl implements Football500OuzImService {

    @Resource
    private Football500OuzImMapper football500OuzImMapper;

    @Override
    public Integer createFootball500OuzIm(Football500OuzImSaveReqVO createReqVO) {
        // 插入
        Football500OuzImDO football500OuzIm = BeanUtils.toBean(createReqVO, Football500OuzImDO.class);
        football500OuzImMapper.insert(football500OuzIm);
        // 返回
        return football500OuzIm.getId();
    }

    @Override
    public void updateFootball500OuzIm(Football500OuzImSaveReqVO updateReqVO) {
        // 校验存在
        validateFootball500OuzImExists(updateReqVO.getId());
        // 更新
        Football500OuzImDO updateObj = BeanUtils.toBean(updateReqVO, Football500OuzImDO.class);
        football500OuzImMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootball500OuzIm(Integer id) {
        // 校验存在
        validateFootball500OuzImExists(id);
        // 删除
        football500OuzImMapper.deleteById(id);
    }

    private void validateFootball500OuzImExists(Integer id) {
        if (football500OuzImMapper.selectById(id) == null) {
            throw exception(FOOTBALL500_OUZ_IM_NOT_EXISTS);
        }
    }

    @Override
    public Football500OuzImDO getFootball500OuzIm(Integer id) {
        return football500OuzImMapper.selectById(id);
    }

    @Override
    public PageResult<Football500OuzImDO> getFootball500OuzImPage(Football500OuzImPageReqVO pageReqVO) {
        return football500OuzImMapper.selectPage(pageReqVO);
    }

}